package com.myblog.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.myblog.entity.Article;
import com.myblog.mapper.ArticleMapper;
import com.myblog.service.ArticleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.myblog.utils.PageResult;
import com.myblog.utils.PageUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author lhj
 * @since 2022-06-10
 */
@Service
public class ArticleServiceImpl extends ServiceImpl<ArticleMapper, Article> implements ArticleService {

    @Autowired
    private ArticleMapper articleMapper;

    @Override
    public PageResult findPage(Integer pageNum,Integer pageSize) {
        PageResult pageResult = PageUtils.getPageResult(getPageInfo(pageSize, pageNum));
        return pageResult;
    }

    private PageInfo<?> getPageInfo(Integer pageSize, Integer pageNum){
        PageHelper.startPage(pageSize, pageNum);
        // 获取分页查询后得数据
        List<Article> articles = articleMapper.selectPage();
        PageInfo<Article> articlePageInfo = new PageInfo<>(articles, pageNum);
        return articlePageInfo;
    }
}
